﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>New Chirp</title>
	<link rel="stylesheet" type="text/css" href="css/default.css" />
	<script src="js/jquery.js" type="text/javascript"></script>
	<script src="js/util.js"   type="text/javascript"></script>
	<script src="js/chirpr.js" type="text/javascript"></script>
	<script type="text/javascript">//<![CDATA[
	/***************************************************************************
	 * Message Fly-out                            http://www.codeplex.com/chirpr
	 *                                          Microsoft Public License (Ms-PL)
	 * Authors
	 *  - Charles Schmidt   2007-08  http://www.pickelhau.be
	 *  - Michael Flanakin  2008-10  http://www.michaelflanakin.com
	 *
	 * page
	 *  - init   : initializes the page
	 *  - submit : handles the form submit
	 *  - cancel : handles the form cancel
	 **************************************************************************/
	var page =
	{
		//***| controls |*******************************************************
		
		head      : null,
		charsLeft : null,
		message   : null,
		info      : null,
		success   : null,
		buttons   : null,
			
		//***| private |********************************************************
		
		__getReplyToUser: function()
		{
			if (util.string.isEmpty(chirpr.replyToUser)) { return; }
			page.head.innerText="reply to "+chirpr.replyToUser;
			page.message.value="@"+chirpr.replyToUser+" ";
		},

		//***| public |*********************************************************
		
		submit: function()
		{
			// TODO: Add better error messages and/or provide link to discussion forums to find out what happened
			if (chirpr.twitter.addMessage(page.message.value))
			{
				// show message
				page.success.innerText     = page.message.value;
				page.success.style.display = "";
				page.message.style.display = "none";
				page.buttons.style.display = "none";
				page.info.className        = "";
				page.info.innerText        = "tweet sent; getting updates now...";
				
				// update messages
				gadget.document.updateMessages();
				
				// close flyout
				gadget.flyout.hide();
				
				// return
				return;
			}
			page.info.className = "error";
			page.info.innerHTML = "uh oh! something went wrong... if you're using special characters, "
				+ "<a href='http://www.codeplex.com/chirpr/Wiki/View.aspx?title=Troubleshooting' onclick='try{page.message.createTextRange().execCommand(\"copy\");}catch(e){/*ignore*/}' "
				+ "title='your text will be copied to the clipboard and a new Chirpr discussion will be opened in a browser'>send us your tweet text</a> so we can find out why";
		},
	
		init: function()
		{
			// load controls
			page.head      = $("#head")[0];
			page.charsLeft = $("#charsLeft")[0];
			page.message   = $("#twitText")[0];
			page.info      = $("#infoMessage")[0];
			page.success   = $("#successMessage")[0];
			page.buttons   = $("#buttons")[0];
			
			// register message textarea
			util.textarea.register(page.message, 140, page.charsLeft);
			page.__getReplyToUser();
		},
		
		keypress: function()
		{
			switch (event.keyCode)
			{
				case 10: // line feed
				case 13: // carriage return
					if (event.ctrlKey)
					{
						page.submit();
					}
					break;
				case 27: // esc
					gadget.flyout.hide();
					break;
				default:
					break;
			}
		}
	};
	//]]></script>
</head>
<body id="message" style="background:#000000; color:#e6f7fc;">

	<div class="content">
		<span id="charsLeft"></span>
		<h1 id="head">what are you doing?</h1>
		<textarea rows="4" id="twitText" onkeypress="page.keypress();"></textarea>
		<div id="successMessage" style="display:none;"></div>
		<div id="infoMessage"></div>
		<div id="buttons">
			<a id="postLink"   title="Ctrl+Enter" href="javascript:this.blur();page.submit();">&#8592; chirp</a>
			<a id="cancelLink" title="Esc"        href="javascript:this.blur();gadget.flyout.hide();">cancel &#8594;</a>
		</div>
	</div>

</body>
</html>
